package com.fh.controller;



import com.fh.model.Users;
import com.fh.service.UsersService;
import com.fh.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
@Api(value = "提供用户添加、修改、删除及查询的相关接⼝",tags = "用户管理")
@CrossOrigin
public class UsersController {

@Resource
private UsersService userService;

    @ApiOperation("⽤户登录接⼝")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string",name = "username", value = "⽤户登录账号",required =
                    true),
            @ApiImplicitParam(dataType = "string",name = "password", value = "⽤户登录密码",required =
                    false,defaultValue = "111111")
    })
    @RequestMapping(value = "/login",method = RequestMethod.GET)
    public ResultVo login(@RequestParam("username") String
                                      username,
                          @RequestParam(value ="password",defaultValue = "111111") String userPwd ){

        return  userService.login(username,userPwd);
 }

    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string",name = "username", value = "⽤户注册账号",required =
                    true),
            @ApiImplicitParam(dataType = "string",name = "password", value = "⽤户注册密码",required =
                    false,defaultValue = "111111")
    })
 @PostMapping("/regist")
 @ApiOperation("注册借口")
 public   ResultVo  regist(@RequestBody Users users){

 return  userService.regist(users.getUsername(),users.getPassword());
 }

    @GetMapping("/query")
    @ApiOperation("分页")
    public ResultVo  query( ){
        return   userService.query();
    }



}
